#include <fstream>
#include <string>
#include <iostream>
#include "Encoding/Encoding.h"
#include "FileTest.h"

using namespace SystemTool;

static void LogFile(char* strMsg)
{
    std::string strFilePath = "/Users/tangyingzhong/Desktop/12.log";
    std::fstream os(strFilePath,std::ios::out);
    os << strMsg << "\n";
    os.close();
}

static void LogFile(const char* strMsg)
{
    std::string strFilePath = "/Users/tangyingzhong/Desktop/12.log";
    std::fstream os(strFilePath,std::ios::out);
    os << strMsg << "\n";
    os.close();
}

void FileTest()
{
    std::string strFilePath = "/Users/tangyingzhong/Desktop/Test/121.log";
    if(!File::IsExisted(strFilePath))
    {
        std::cout << "File is not existed and create it\n";
        File::Create(strFilePath);
        return;
    }

    File::Rename(strFilePath,"/Users/tangyingzhong/Desktop/12.log");
    File::Delete("/Users/tangyingzhong/Desktop/12.log");
    File::Create("/Users/tangyingzhong/Desktop/Test/121.log");

    bool bRet = File::MoveTo(strFilePath,"/Applications/");
    File::Delete("/Applications/121.log");
    File::Create("/Users/tangyingzhong/Desktop/Test/121.log");
    File::CopyTo(strFilePath,"/Applications/");
    File::Delete("/Applications/121.log");
    File::SetWritable(strFilePath,false);
    File::SetExcutable(strFilePath,true);
    File::SetWritable(strFilePath,true);
    File::SetExcutable(strFilePath,false);
    
    unsigned long long iFileSize = File::GetSize(strFilePath);
    LogFile(std::to_string(iFileSize).c_str());

    std::string strFileName = File::GetFileName(strFilePath);
    std::string strParentDirPath = File::GetFileParentDirPath(strFilePath);
    std::cout << strFileName << std::endl;
    std::cout << strParentDirPath << std::endl;
    
    return;
}
